<%@page import="com.bci.pwtz.service.CompanyRoleService"%>
<%@page import="com.bci.pwtz.service.CompanyService"%>
<%@page import="com.bci.pwtz.mysql.model.Company"%>
<%@page import="com.bci.pwtz.common.util.SpringUtil"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.bci.pwtz.mysql.model.CompanyUser"%>
<%@ page import="com.bci.pwtz.common.PwtzConstants"%>
<%
CompanyUser companyUser = (CompanyUser) session.getAttribute("user");
String hpath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+"/";
String currentCompanName = "";
if(companyUser!=null)
{ 
    CompanyService companyService = (CompanyService)SpringUtil.getBean("companyService");
	CompanyRoleService headCompanyRoleService = (CompanyRoleService)SpringUtil.getBean("companyRoleService");
    
	Long currentCompanyId = companyUser.getLastCompanyId();
	
	if(currentCompanyId==null)
	{
	    response.sendRedirect(hpath+"user/m/userflow.jsp");
        return;
	}
	
	List<Company> companyList = companyService.findCompanyByUserId(companyUser.getCompanyUserId());
    if(companyList == null || companyList.size() == 0)
    {
        response.sendRedirect(hpath+"user/m/userflow.jsp");
        return;
    }
	
	Company currentCompany = companyService.load(currentCompanyId);
	if(currentCompany!=null)
	{
	    currentCompanName = currentCompany.getCompanyName();
	    
	    if(session.getAttribute("isSuper")==null||session.getAttribute("actionCodes")==null||session.getAttribute("companyEnable")==null)
		{
		    session.setAttribute("isSuper", headCompanyRoleService.checkIsCreator(companyUser.getCompanyUserId(), currentCompanyId));
		    session.setAttribute("actionCodes", headCompanyRoleService.getUserActionCodes(companyUser.getCompanyUserId(), currentCompanyId));
		    session.setAttribute("companyEnable", currentCompany.getStatus()==1);
		}
	}   

	else
	{
	    response.sendRedirect(hpath+"user/m/userflow.jsp");
        return;
	}
	
	
	
	
	
%>
    <div class="pwsj_top">
		<img class="pwsj_logo" src="<%=hpath %>user/images/logo.png" alt=""  />
		<p class="dwmc"><%=currentCompanName %></p>
		<p class="qhdw_p"><a class="qhdw" href="<%=hpath %>user/m/mycompany.jsp">[ 切换单位 ]</a></p>
		<p class="pwsj_welcome"><%=companyUser.getLoginName() %>，你好！欢迎使用配网数据助手！</p>
		<ul class="top_menu_ul">
			<li class="top_menu_li"><a href="<%=hpath %>user/m/index.jsp">系统主页</a></li>
			<li class="top_menu_li"><a href="<%=hpath %>user/m/edituserinfo.jsp">资料修改</a></li>
			<li class="top_menu_li"><a href="<%=hpath %>user/m/modifypassword.jsp">密码修改</a></li>
			<li class="logout"><a  onclick="logout();return false;" class="esc">[ 退出登录 ]</a></li>
		</ul>
	</div>
<%}else{
	response.sendRedirect(hpath+"user/login.jsp");
	return;
}%>
<script>
function logout()
{
		if(confirm('你是否退出该系统?'))
			{
			location.href="<%=hpath%>user/companyuser/logout?loginUrl="+escape('<%=hpath%>user/login.jsp');
			}
}
</script>   
